import $http from "../assets/js/http";

// 床位查询
export async function getCostDetail({
  jobNumber,
  name,
  room,
  page,
  time,
  _time,
  judge
}) {
  _time = JSON.stringify(_time);
  return $http.post("cost/Cost/getCostDetail", {
    jobNumber,
    name,
    room,
    page,
    _time,
    judge
  });
}

// 获取免扣/销假单
export async function getFreeCost({
  _time,
  name,
  jobNumber,
  type,
  page
}) {
  let newTime = JSON.stringify(_time);
  return $http.post("cost/Cost/getFreeCost", {
    newTime,
    name,
    jobNumber,
    type,
    page
  });
}

// 查询人员信息
export async function getPersonInfo(jobNumber) {
  return $http.post("cost/Cost/getPersonInfo", {
    jobNumber
  });
}

// 新增免扣\销假单
export async function newFree({
  type,
  jobNumber,
  name,
  department,
  _time,
  reason,
  remark,
  sfz
}) {
  let newTime = JSON.stringify(_time);
  return $http.post("cost/Cost/newFree", {
    type,
    jobNumber,
    name,
    department,
    newTime,
    reason,
    remark,
    sfz
  });
}

// 计算单人费用
export async function singleCost(data) {
  data._outDate = parseInt(data.outDate.getTime()) / 1000;
  console.log(data._outDate);
  return $http.post("cost/Cost/singleCost", data);
}

// 单人费用导入
export async function importSingleCost({
  affiliationserial,
  dor,
  floor,
  room,
  jobNumber,
  name,
  coldCost,
  hotCost,
  electricCost,
  avgColdCost,
  avgElectricCost,
  avgHotCost,
  singleDay,
  totalCost,
  _outDate,
  cold,
  hot,
  electric
}) {
  // let newDate = parseInt(outDate.getTime() / 1000);
  return $http.post("cost/Cost/importSingleCost", {
    affiliationserial,
    dor,
    floor,
    room,
    jobNumber,
    name,
    coldCost,
    hotCost,
    electricCost,
    avgColdCost,
    avgElectricCost,
    avgHotCost,
    singleDay,
    totalCost,
    _outDate,
    cold,
    hot,
    electric
  });
}

// 获取楼层、房间电表度数
export async function getMeter({
  _area,
  _dorm,
  _floor,
  _roomNumber,
  roomPage,
  floorPage
}) {
  return $http.post("cost/Cost/getMeter", {
    _area,
    _dorm,
    _floor,
    _roomNumber,
    roomPage,
    floorPage
  });
}

// 期初
export async function beginning() {
  return $http.post("cost/Cost/beginning");
}

// 修改房间数据
export async function editRoomMeter(data) {
  return $http.post("cost/Cost/editRoomMeter", data);
}

// 修改楼层数据
export async function editFloorMeter(data) {
  return $http.post("cost/Cost/editFloorMeter", data);
}

// 期末结算
export async function monthEndCost(data) {
  return $http.post("cost/Cost/monthEndCost", data);
}

// 计算自损耗费用
export async function costZSH(meter, roomNumber, area, dorm, time, floor) {
  let _meter = JSON.stringify(meter);
  let _time = parseInt(time.getTime()) / 1000;
  return $http.post("cost/Cost/costZSH", {
    _meter,
    roomNumber,
    area,
    dorm,
    _time,
    floor
  });
}
